package com.geostar.constructionland.analyse.service.analyse.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geostar.constructionland.common.entity.logs.JsydFxrz;
import com.geostar.constructionland.common.entity.logs.LogAnalyse;
import com.geostar.constructionland.common.mapper.logs.JsydFxrzMaper;
import com.geostar.constructionland.common.mapper.logs.LogAlyMapper;
import com.geostar.constructionland.analyse.service.analyse.LogAlyService;
import com.geostar.constructionland.common.global.AnalyseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

/**
 * @author yelll
 * @since 2020-6-18 15:12
 **/
@Service
public class LogAlyServiceImpl extends ServiceImpl<LogAlyMapper, LogAnalyse> implements LogAlyService {
    @Autowired
    JsydFxrzMaper jsydFxrzMaper;

    @Override
    public void saveLogAnalyseAndFxrz(LogAnalyse logAnalyse) {
        JsydFxrz jsydFxrz = new JsydFxrz();
        jsydFxrz.setBz(logAnalyse.getErrorMsg());
        jsydFxrz.setCzlx(logAnalyse.getAnalyseType());
        jsydFxrz.setFxbs(logAnalyse.getAlyCode());
        jsydFxrz.setFxlx(logAnalyse.getAnalyseType());
        jsydFxrz.setFxsj(new Date());
        jsydFxrz.setFxjg("false");
        if(logAnalyse.getAlyResult().equals(",1,1")){
            jsydFxrz.setFxjg("true");
        }
        jsydFxrz.setYwid(logAnalyse.getYwid());
        jsydFxrzMaper.insert(jsydFxrz);
        if(!logAnalyse.getAnalyseTypeMapped().equals(AnalyseType.YPHXFX)){
            jsydFxrz.setFxrzid(UUID.randomUUID().toString().replaceAll("-",""));
            jsydFxrz.setFxlx("CDYPHXFX");
            jsydFxrzMaper.insert(jsydFxrz);
        }else if(logAnalyse.getAnalyseTypeMapped().equals(AnalyseType.TZHDLFX)){
            String TZHGDFX_e = "TZHGDFX"+logAnalyse.getAnalyseType().substring(7);
            jsydFxrz.setFxrzid(UUID.randomUUID().toString().replaceAll("-",""));
            jsydFxrz.setFxlx(TZHGDFX_e);
            jsydFxrzMaper.insert(jsydFxrz);
            jsydFxrz.setFxrzid(UUID.randomUUID().toString().replaceAll("-",""));
            String QSFX_e = "QSFX"+logAnalyse.getAnalyseType().substring(7);
            jsydFxrz.setFxlx(QSFX_e);
            jsydFxrzMaper.insert(jsydFxrz);
        }
    }
}
